package day03;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.w3c.dom.ls.LSOutput;
import utilspackage.JDBCUtils;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.sql.Connection;
import java.util.Properties;

/**
 * @author Xiao
 * @date 2021/8/20
 */
public class DruidDemo {
    /**
     * 使用步骤：
     * ① 包 druid-1.1.12.jar
     * ② 定义配置文件
     * ③ 加载配置文件
     * ④ 获取数据库连接池对象
     * ⑤ 获取连接
     */
    public static void main(String[] args) throws Exception{
        Connection conn = JDBCUtils.getConnection();
        System.out.println(conn);
        //打印当前的路径
        System.out.println(System.getProperty("user.dir"));
    }

    private static Connection getConnection() throws Exception {
        Properties prop = new Properties();
        FileInputStream fis = new FileInputStream("JDBC/src/druid.properties");
        prop.load(fis);
        fis.close();
        DataSource dataSource = DruidDataSourceFactory.createDataSource(prop);
        Connection conn = dataSource.getConnection();
        return conn;
    }
}
